package com.fac.controller.admin;

import com.fac.dto.LeaseOrderPageQueryDTO;
import com.fac.dto.LeaseOrderReturnDTO;
import com.fac.result.PageResult;
import com.fac.result.Result;
import com.fac.service.LeaseOrderService;
import com.fac.vo.LeaseOrderVO;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * 租赁订单管理Controller
 */
@RestController
@RequestMapping("/admin/leaseOrders")
@Api(tags = "管理端-租赁订单管理接口")
@Slf4j
public class LeaseOrderController {

    @Autowired
    private LeaseOrderService leaseOrderService;

    /**
     * 分页查询租赁订单
     *
     * @param queryDTO 查询条件
     * @return 分页结果
     */
    @GetMapping
    @ApiOperation("分页查询租赁订单")
    public Result<PageResult> page(LeaseOrderPageQueryDTO queryDTO) {
        log.info("分页查询租赁订单：{}", queryDTO);
        PageResult pageResult = leaseOrderService.pageQuery(queryDTO);
        return Result.success(pageResult);
    }

    /**
     * 确认归还设备
     *
     * @param orderId 订单ID
     * @param returnDTO 归还信息
     * @return 更新后的订单信息
     */
    @PutMapping("/{orderId}/return")
    @ApiOperation("确认归还设备")
    public Result<LeaseOrderVO> confirmReturn(
            @PathVariable Long orderId,
            @RequestBody LeaseOrderReturnDTO returnDTO) {
        log.info("确认归还设备，订单ID：{}，归还信息：{}", orderId, returnDTO);
        LeaseOrderVO orderVO = leaseOrderService.confirmReturn(orderId, returnDTO);
        return Result.success(orderVO);
    }
} 